package com.aust.furniture.controller;

import com.aust.furniture.vo.EchartsData;
import com.aust.furniture.vo.OwInfoCountForEchartsData;
import com.aust.furniture.vo.SaleDataForEcharts;
import com.aust.furniture.mapper.OwinfoMapper;
import com.aust.furniture.mapper.SaleinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author wzy
 * @Date 2024/6/7 15:26--
 * @description: 数据展示
 */
@Controller
@RequestMapping(value = "/echarts")
public class EchatsController {

    @Autowired
    private OwinfoMapper owinfoMapper;

    @Autowired
    private SaleinfoMapper saleinfoMapper;
    @RequestMapping()
    public String gotoEcharts(){
        return "/echarts";
    }


    /**
     * 获取入库数据的统计
     * @return
     */
    @ResponseBody
    @RequestMapping("/warehousingData")
    public EchartsData getWarehousingData(){
        //获取近近一个月的入库数据
        List<OwInfoCountForEchartsData> countData = owinfoMapper.getWarehousingData();
        ArrayList<String> xAxisData = new ArrayList<>();
        ArrayList<Integer> seriesData = new ArrayList<>();
        for (OwInfoCountForEchartsData countDatum : countData) {
            xAxisData.add(countDatum.getFname());
            seriesData.add(countDatum.getCount());
        }
        return new EchartsData(xAxisData,seriesData);
    }
    /**
     * 获取销售数据的统计
     * @return
     */
    @ResponseBody
    @RequestMapping("/saleData")
    public List<SaleDataForEcharts> getSaleInfoData(){
        //获取近近一年的销售数据
        List<SaleDataForEcharts> countData = saleinfoMapper.getSaleInfoData();
        return countData;
    }
}
